package com.coldchain.message.Listener;

import com.alibaba.fastjson.JSONObject;
import com.coldchain.message.core.constant.QueryType;

import com.coldchain.message.core.entity.SMSMsg;
import com.coldchain.common.util.AliyunSmsUtil;


import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component;


/**
 * @ClassName SMSListener
 * @Description TODO
 * @Author fangliai
 * @Date 2018/9/20 17:34
 * @Vesion 1
**/
 @Component
public class SMSListener {

    /**
     * 短信事件
      *@param msg
     * @param message
     * @param channel
     */
    @RabbitListener(queues = QueryType.CODE)
    public void execute(@Payload com.coldchain.message.core.entity.Message<SMSMsg> msg, Message message, Channel channel){

        System.out.println("收到新SMS消息:"+JSONObject.toJSONString(msg));
        try {
            AliyunSmsUtil.sendSms(
                    msg.getContent().getPhone(),msg.getContent().getContent());

        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
